<html>
<head><meta charset="utf-8"><title>crate version mismatch error messages · t-compiler/wg-diagnostics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/index.html">t-compiler/wg-diagnostics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/crate.20version.20mismatch.20error.20messages.html">crate version mismatch error messages</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="179707622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/crate%20version%20mismatch%20error%20messages/near/179707622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/crate.20version.20mismatch.20error.20messages.html#179707622">(Nov 02 2019 at 16:00)</a>:</h4>
<p>Hi everyone, i would like to help with <a href="https://github.com/rust-lang/rust/issues/22750" target="_blank" title="https://github.com/rust-lang/rust/issues/22750">https://github.com/rust-lang/rust/issues/22750</a> but i'm stuck with the implementation, maybe someone could help me out?</p>
<p>i found the method that reports the <code>trait Foo is not implemented for Bar</code> error <a href="https://github.com/rust-lang/rust/blob/87cbf0a547aaf9e8a7fc708851ecf4bc2adab5fd/src/librustc/traits/error_reporting.rs#L755" target="_blank" title="https://github.com/rust-lang/rust/blob/87cbf0a547aaf9e8a7fc708851ecf4bc2adab5fd/src/librustc/traits/error_reporting.rs#L755">here</a> and I thought I'd add a function call there that looks at the traits that <code>traif_ref.self_ty()</code> actually implements and generate a helpful message if any of those traits has the same name(/path) as <code>trait_ref</code></p>
<p>Assuming that's a reasonable approach, I don't know how to get the implemented traits of <code>trait_ref.self_ty()</code>. All further queries in <code>TyCtxt</code> (or the <code>HIR-Map</code>) seem to require a <code>DefId</code> or <code>HirId</code>, and I haven't found a way to get the <code>DefId</code> of a <code>Ty</code>. Also, I'm not sure how to get the implemented traits of a type, <del>should I call <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TyCtxt.html#method.for_each_relevant_impl" target="_blank" title="https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TyCtxt.html#method.for_each_relevant_impl">TyCtxt::for_each_relevant_impl</a> and do the work in a closure?</del> I just realized that this method also receives the <code>DefId</code> of a trait, so it won't give me the impls of <em>all</em> traits of a type, only of <em>one</em>.</p>
<p>Do I get <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TyCtxt.html#method.all_traits" target="_blank" title="https://doc.rust-lang.org/nightly/nightly-rustc/rustc/ty/struct.TyCtxt.html#method.all_traits">all_traits</a> and then try to find an impl for the type <code>Foo</code> for diagnostics? Seems very wasteful.<br>
I'd expect there to be a helper function that gives me all traits a type implements... Although I realize that the trait solver is very complicated of course</p>



<a name="180280090"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/crate%20version%20mismatch%20error%20messages/near/180280090" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Esteban Küber <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/crate.20version.20mismatch.20error.20messages.html#180280090">(Nov 08 2019 at 22:44)</a>:</h4>
<blockquote>
<p>Seems very wasteful.<br>
<span class="user-mention silent" data-user-id="219762">Timo Freiberg</span> as long as the wastefulness only happens outside of the happy path (only when emitting errors), that is usually ok.</p>
</blockquote>



<a name="180457641"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/147480-t-compiler/wg-diagnostics/topic/crate%20version%20mismatch%20error%20messages/near/180457641" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Timo Freiberg <a href="https://rust-lang.github.io/zulip_archive/stream/147480-t-compiler/wg-diagnostics/topic/crate.20version.20mismatch.20error.20messages.html#180457641">(Nov 11 2019 at 20:34)</a>:</h4>
<p>Thanks for the reply :) I'm going to try working on it a little bit more.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>